package net.villonanny.type;

import java.util.HashMap;

public enum TribeType {
	// String values must match language keyword, e.g. key.romans = Romer
	ROMANS("romans"),
	GAULS("gauls"),
	TEUTONS("teutons") 
	;
	// This is needed to convert from String to enum
	private static HashMap<String, TribeType> fromStringMap;
	
	static {
		fromStringMap = new HashMap<String, TribeType>();
		TribeType[] values = TribeType.values();
		for (int i = 0; i < values.length; i++) {
			TribeType m = values[i];
			fromStringMap.put(m.stringValue.toLowerCase(), m);
		}
	}
	private final String stringValue;

	private TribeType(String name) {
		this.stringValue = name;
	}
	
	public String toString() {
		return stringValue;
	}

	public static TribeType fromInt(int num) {
		return TribeType.values()[num]; // Starts at 0
	}
	
	public int toInt() {
		return ordinal();
	}
	
	/**
	 * Convert from string to TribeType
	 * @param tribe the tribe ("romans", "gauls", "teutons")
	 * @return
	 */
	public static TribeType fromString(String tribe) {
		if (tribe==null) {
			return null;
		}
		return fromStringMap.get(tribe.toLowerCase());
	}
}
